package com.lyf.boot.modules.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.lyf.boot.base.system.dao.BaseOssConfigDao;
import com.lyf.boot.base.system.entity.OssConfig;
import com.lyf.boot.model.OssConfigProperties;
import com.lyf.boot.modules.system.service.IOssConfigService;
import com.lyf.boot.service.IFileStorageService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Luyufan
 * @date 2023/8/15 13:55
 */
@Service
@RequiredArgsConstructor
public class OssConfigServiceImpl implements IOssConfigService {

    private final BaseOssConfigDao baseOssConfigDao;

    private final IFileStorageService fileStorageService;


    @Override
    public void initOssConfig() {
        List<OssConfig> ossConfigs = baseOssConfigDao.selectEnabledOssConfig();
        if(CollUtil.isEmpty(ossConfigs)){
            return;
        }
        ossConfigs.forEach(ossConfig -> fileStorageService.addFileStorage(BeanUtil.copyProperties(ossConfig, OssConfigProperties.class)));
    }

    @Override
    public String getDefaultPlatform() {
        return baseOssConfigDao.selectDefaultOssPlatform();
    }
}
